home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Milan_1991 / Devcon91.1 / Libraries / Commodities / IHelp / ihelp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-01  |  5.1 KB  |  202 lines

  1.  
  2.    /***********************************************************************
  3.    *                                                                      *
  4.    *                            COPYRIGHTS                                *
  5.    *                                                                      *
  6.    *   Copyright (c) 1990  Commodore-Amiga, Inc.  All Rights Reserved.    *
  7.    *                                                                      *
  8.    ***********************************************************************/
  9.  
  10. #include "app.h"
  11. #include <intuition/intuitionbase.h>
  12.  
  13. #define CYCLE        1L
  14. #define CYCLEBACK    2L
  15. #define MAKEBIG      3L
  16. #define MAKESMALL    4L
  17. #define CYCLESCREEN  5L
  18. #define ZIPWINDOW    6L
  19.  
  20. #define   IMINWIDTH   40
  21. #define   IMINHEIGHT   30
  22. #define   MIN(A,B)   (((A)<(B))?(A):(B))
  23. #define   MAX(A,B)   (((A)>(B))?(A):(B))
  24.  
  25. void makesize(LONG);
  26. void cyclebackward(void);
  27. void cycleforward(void);
  28. void cyclescreen(void);
  29. void zipwindow(void);
  30.  
  31. BOOL setupIHelp()
  32. {
  33.    LONG         error;
  34.  
  35.    AttachCxObj(broker,
  36.       HotKey( ArgString(ttypes, "CYCLE", "f1"), cxport, CYCLE) );
  37.    AttachCxObj(broker,
  38.       HotKey( ArgString(ttypes, "MAKEBIG", "f2"),  cxport, MAKEBIG) );
  39.    AttachCxObj(broker,
  40.       HotKey( ArgString(ttypes, "MAKESMALL", "f3"), cxport, MAKESMALL) );
  41.    AttachCxObj(broker,
  42.       HotKey( ArgString(ttypes, "CYCLESCREEN", "f4"), cxport, CYCLESCREEN) );
  43.    AttachCxObj(broker,
  44.       HotKey( ArgString(ttypes, "ZIPWINDOW", "f5"), cxport, ZIPWINDOW) );
  45.  
  46.    if (error = CxObjError(broker))
  47.    {
  48.       D( printf("accumulated broker error %ld\n", error) );
  49.       return(0);
  50.    }
  51.    return(1);
  52. }
  53. VOID MyHandleCXMsg(id)
  54. ULONG id;
  55. {
  56.    switch(id)
  57.    {
  58.       case CYCLE:
  59.             D( printf("cycleforward\n") );
  60.             cycleforward();
  61.             break;
  62.       case MAKEBIG:
  63.             D( printf("makebig\n") );
  64.             makesize((int) MAKEBIG);
  65.             break;
  66.       case MAKESMALL:
  67.             D( printf("makesmall\n") );
  68.             makesize((int) MAKESMALL);
  69.             break;
  70.       case CYCLESCREEN:
  71.             cyclescreen();
  72.             break;
  73.       case ZIPWINDOW:
  74.             zipwindow();
  75.             break;
  76.    }
  77. }
  78.  
  79. void makesize(command)
  80. LONG command;
  81. {
  82.    ULONG         ilock;
  83.    struct Window   *awindow;
  84.    struct Screen   *ascreen;
  85.    SHORT         deltaw;
  86.    SHORT         deltah;
  87.    ULONG         Sizing;
  88.  
  89.    ilock = LockIBase(0L);
  90.    awindow = IntuitionBase->ActiveWindow;
  91.    ascreen = awindow->WScreen;
  92.  
  93.    switch (command)
  94.    {
  95.       case MAKESMALL:
  96.             deltaw = MAX(awindow->MinWidth, IMINWIDTH) - awindow->Width;
  97.             deltah = MAX(awindow->MinHeight, IMINHEIGHT) - awindow->Height;
  98.             break;
  99.       case MAKEBIG:
  100.             deltaw =MIN(ascreen->Width - awindow->LeftEdge, (unsigned) awindow->MaxWidth) - awindow->Width;
  101.             deltah =MIN(ascreen->Height-awindow->TopEdge, (unsigned) awindow->MaxHeight) - awindow->Height;
  102.             break;
  103.       default:
  104.             deltaw = 0;
  105.             deltah = 0;
  106.    }
  107.    if(awindow->Flags & WINDOWSIZING)
  108.       Sizing=TRUE;
  109.    else Sizing=FALSE;
  110.  
  111.    UnlockIBase(ilock);
  112.  
  113.    if(Sizing)
  114.       SizeWindow(awindow, (LONG) deltaw, (LONG) deltah);
  115. }
  116.  
  117. void cycleforward()
  118. {
  119.    LONG         ilock;
  120.    struct Window   *awindow;
  121.    struct Screen   *ascreen;
  122.    struct Layer   *rearlayer;      /* rearmost so far      */
  123.    struct Layer   *layer;         /* runs through layers   */
  124.    struct Window   *lwindow;      /* layer->Window      */
  125.  
  126.  
  127.    ilock = LockIBase(0L);
  128.    awindow = IntuitionBase->ActiveWindow;
  129.    ascreen = awindow->WScreen;
  130.  
  131.    D( printf("active window/screen: %lx/%lx\n", awindow, ascreen) );
  132.  
  133.    /* for now, only pull this stuff on the workbench   */
  134.    if ((ascreen->Flags & SCREENTYPE) != WBENCHSCREEN)
  135.    {
  136.       D( printf("not wbscreen\n") );
  137.       UnlockIBase(ilock);
  138.       goto OUT;
  139.    }
  140.  
  141.    /* find rearmost layer which is not a backdrop window,
  142.     * nor the bar layer, nor a WBENCHWINDOW
  143.     */
  144.    rearlayer = NULL;
  145.    for (layer = ascreen->LayerInfo.top_layer;layer; layer = layer->back)
  146.    {
  147.       lwindow = (struct Window *) layer->Window;
  148.       D( printf("layer %lx window %lx\n",layer, lwindow) );
  149.       if (layer == ascreen->BarLayer)   
  150.       {
  151.          D( printf("is bar layer\n") );
  152.          continue;
  153.       }
  154.       if (layer->Flags & LAYERBACKDROP)
  155.       {
  156.          D( printf("backdrop layer\n") );
  157.          continue;
  158.       }
  159.       if (lwindow->Flags & WBENCHWINDOW)
  160.       {
  161.          D( printf("skipping wbench window\n") );
  162.          continue;
  163.       }
  164.  
  165.       rearlayer = layer;
  166.    }
  167.    D( printf("let's try it\n") );
  168.    UnlockIBase(ilock);
  169.    D( printf("unlocked\n") );
  170.  
  171.    if (rearlayer)
  172.    {
  173.       lwindow = (struct Window *) rearlayer->Window;
  174.       D( printf("window of choice: %lx\n") );
  175.       WindowToFront(lwindow);
  176.       if (lwindow != awindow) ActivateWindow(lwindow);
  177.    }
  178.  
  179. OUT:
  180.    D( printf("cycleback done\n") );
  181.    return;
  182.  
  183. }
  184.  
  185. void cyclescreen()
  186. {
  187.    ULONG         ilock;
  188.  
  189.    D( printf("cyclescreen()\n") );
  190.    ScreenToBack(IntuitionBase->FirstScreen);
  191. }
  192.  
  193. void zipwindow(void)
  194. {
  195.    ULONG         ilock;
  196.    struct Window   *awindow;
  197.  
  198.    awindow = IntuitionBase->ActiveWindow;
  199.  
  200.    ZipWindow(awindow);
  201. }
  202.